home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / glibc108.gz / glibc108 / glibc-1.08.1 / sysdeps / mach / hurd / i386 / msging-p.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-21  |  2.4 KB  |  68 lines

  1. /* Test a Mach thread_state for being in a mach_msg syscall.  i386 version.
  2. Copyright (C) 1994 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4.  
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public License as
  7. published by the Free Software Foundation; either version 2 of the
  8. License, or (at your option) any later version.
  9.  
  10. The GNU C Library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. Library General Public License for more details.
  14.  
  15. You should have received a copy of the GNU Library General Public
  16. License along with the GNU C Library; see the file COPYING.LIB.  If
  17. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  18. Cambridge, MA 02139, USA.  */
  19.  
  20. #include <hurd/signal.h>
  21. #include <mach/thread_status.h>
  22. #include <string.h>
  23. #include <setjmp.h>
  24.  
  25. extern jmp_buf _hurd_sigthread_fault_env;
  26.  
  27. /* Return nonzero if STATE indicates a thread
  28.    that is blocked in a mach_msg system call.  */
  29. int
  30. _hurd_thread_state_msging_p (void *state, mach_port_t *port)
  31. {
  32.   if (setjmp (_hurd_sigthread_fault_env))
  33.     /* The PC or SP pointed at bogus memory.  */
  34.     return 0;
  35.   else
  36.     {
  37.       struct i386_thread_state *ts = state;
  38.       const unsigned char *pc = (void *) ts->eip;
  39.       static const unsigned char lcall[] = { 0x9a, 0, 0, 0, 0, 7, 0 };
  40.       if (ts->eax == -25 &&    /* mach_msg_trap XXX */
  41.       !memcmp (pc - sizeof (lcall), lcall, sizeof (lcall)))
  42.     {
  43.       /* We are blocked in a mach_msg_trap system call.
  44.          Examine the parameters to find the receive right.  */
  45.       struct mach_msg_trap_args
  46.         {
  47.           /* This is the order of arguments to mach_msg_trap.  */
  48.           mach_msg_header_t *msg;
  49.           mach_msg_option_t option;
  50.           mach_msg_size_t send_size;
  51.           mach_msg_size_t rcv_size;
  52.           mach_port_t rcv_name;
  53.           mach_msg_timeout_t timeout;
  54.           mach_port_t notify;
  55.         } *args;
  56.       /* The arguments begin after one word at the top of stack
  57.          that is the address mach_msg_trap will return to.  */
  58.       args = (void *) &((int **) ts->uesp)[1];
  59.       /* Now ARGS points just past the end of the arguments;
  60.          decrement it to point at the beginning of the arguments.  */
  61.       --args;
  62.       *port = args->rcv_name;
  63.       return 1;
  64.     }
  65.       return 0;
  66.     }
  67. }
  68.